import 'package:hrt/resources/app_colors.dart';
import 'package:hrt/widgets/secondary_action_button.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

class StatisticsPage extends StatelessWidget {
  const StatisticsPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.background,
      body: SafeArea(
        child: Center(
          child: ConstrainedBox(
            constraints: const BoxConstraints(maxWidth: 1000),
            child: Column(
              children: [
                Container(
                  margin: const EdgeInsets.only(top: 24),
                  child: const Text(
                    "战绩",
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      fontSize: 24,
                      color: AppColors.darkGreyText,
                    ),
                  ),
                ),
                const Expanded(child: SizedBox.shrink()),
                FutureBuilder<SharedPreferences>(
                  future: SharedPreferences.getInstance(),
                  builder: (context, snapshot) {
                    if (!snapshot.hasData) {
                      return const SizedBox();
                    }
                    final SharedPreferences sp = snapshot.data!;
                    return Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Text(
                          "胜利: ${sp.getInt("stats_胜利") ?? 0}",
                          style: const TextStyle(
                            fontSize: 16,
                            color: AppColors.darkGreyText,
                          ),
                        ),
                        const SizedBox(height: 6),
                        Text(
                          "失败: ${sp.getInt("stats_失败") ?? 0}",
                          style: const TextStyle(
                            fontSize: 16,
                            color: AppColors.darkGreyText,
                          ),
                        ),
                        const SizedBox(height: 6),
                        Text(
                          "平局: ${sp.getInt("stats_平局") ?? 0}",
                          style: const TextStyle(
                            fontSize: 16,
                            color: AppColors.darkGreyText,
                          ),
                        ),
                      ],
                    );
                  },
                ),
                const Expanded(child: SizedBox.shrink()),
                Padding(
                  padding: const EdgeInsets.only(bottom: 16),
                  child: SecondaryActionButton(
                    onTap: () => Navigator.of(context).pop(),
                    text: "返回首页",
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
